winbrew_cli\services\startup/process.rs
1//! Process-global service initialization for CLI startup.
2//!
3//! This submodule owns the side effects that must happen before any command is
4//! dispatched: tracing setup, database initialization, and runtime cleanup.
5//! Keeping these steps here makes the startup contract explicit and prevents
6//! them from being mixed into config loading or command dispatch.
7//!
8//! The order is deliberate:
9//!
10//! - [`crate::services::bootstrap::logging::init`] must run first so later
11//! failures can be written to the console and file sink.
12//! - [`crate::database::init`] seeds the process-wide connection state used by
13//! command handlers and cleanup routines.
14//! - [`crate::services::bootstrap::init_runtime`] installs Ctrl+C handling and
15//! replays bootstrap cleanup, which depends on the database already being
16//! available.
17
18use anyhow::Result;
19
20use crate::CommandContext;
21use crate::database;
22use crate::services::bootstrap;
23
24/// Initialize the global services required for a fully hydrated CLI process.
25///
26/// This is intentionally a side-effecting step. It does not inspect or mutate
27/// the command itself; it only prepares process-wide facilities that command
28/// execution relies on.
29pub(super) fn init(context: &CommandContext) -> Result<()> {
30 bootstrap::logging::init(
31 &context.app().paths.logs,
32 &context.app().log_level,
33 &context.app().file_log_level,
34 )?;
35 database::init(&context.app().paths)?;
36 bootstrap::init_runtime()?;
37
38 Ok(())
39}